package com.dhj.jvmstudy.chapter08;

/**
 * -XX:+PrintGCDetails
 */
public class LocalVarGC {

    public void localVarGC1(){
        // 不会回收，从新生代到老年代
        byte[] buffer = new byte[10*1024*1024]; // 10MB
        System.gc();
    }

    public void localVarGC2(){
        // 回收
        byte[] buffer = new byte[10*1024*1024];
        buffer = null;
        System.gc();
    }

    public void localVarGC3(){
        {
            // 不会回收，可以通过jclasslib查看字节指令。
            byte[] byffer = new byte[10*1024*1024];
        }
        System.gc();
    }

    public void localVarGC4(){
        {
            // 会回收，因为buffer的变量槽slot被value占用，对象就可以被回收
            byte[] buffer = new byte[10*1024*1024];
        }
        int value = 10;
        System.gc();
    }

    public void localVarGC5(){
        // localVarGC1的变量会被回收
        localVarGC1();
        System.gc();
    }

    public static void main(String[] args) {
        LocalVarGC localVarGC = new LocalVarGC();
        localVarGC.localVarGC1();
    }


}
